﻿<views:MvxWpfView
	x:Class="Sidvall.WorkItemManager.UI.Wpf.Views.ServerView"
	xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:vms="clr-namespace:Sidvall.WorkItemManager.UI.ViewModels;assembly=Sidvall.WorkItemManager.UI"
	xmlns:Controls="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Controls" 
	xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
	mc:Ignorable="d" 
	d:DesignHeight="500" d:DesignWidth="600">

	<views:MvxWpfView.Resources>
		<Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
		<Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True"/>
	</views:MvxWpfView.Resources>

	<Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:ServerViewModel}}">
		<Grid.Background>
			<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.InactiveBorderColorKey}}"/>
		</Grid.Background>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition/>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="200" />
			<ColumnDefinition />
		</Grid.ColumnDefinitions>

		<Controls:HeaderControl Grid.ColumnSpan="2" HeaderCaption="Servers" />

		<Grid Grid.Row="1">
			<Grid.Background>
				<SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
			</Grid.Background>
			<StackPanel Orientation="Horizontal">
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Add.png" 
										ToolTip="Add server" ButtonCommand="{Binding AddServerCommand}" />

			</StackPanel>
		</Grid>
		<DataGrid Grid.Row="2" Grid.RowSpan="2" ItemsSource="{Binding ServerConnections}" AutoGenerateColumns="False" HeadersVisibility="None" 
				  CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" SelectionMode="Single" CanUserAddRows="False" 
				  SelectedItem="{Binding ActiveServerConnection, Mode=TwoWay}" IsReadOnly="True">
			<i:Interaction.Triggers>
				<i:EventTrigger EventName="SelectionChanged">
					<i:InvokeCommandAction Command="{Binding SelectTreeItemCommand}" />
				</i:EventTrigger>
			</i:Interaction.Triggers>
			<DataGrid.Columns>
				<DataGridTemplateColumn Width="*">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Grid ToolTip="Server" Background="#FF6AA8C5">
								<Grid.RowDefinitions>
									<RowDefinition Height="40" />
								</Grid.RowDefinitions>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Image Margin="5" Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Server.png" Stretch="UniformToFill" />
								<TextBlock Grid.Column="1" Text="{Binding Name}" FontWeight="Bold" Margin="5,0,0,0" VerticalAlignment="Center" FontSize="14" ToolTip="{Binding ItemTooltip}" ForceCursor="False" />
							</Grid>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</DataGridTemplateColumn>
			</DataGrid.Columns>
		</DataGrid>

		<Grid Grid.Row="1" Grid.Column="1">
			<Grid.Background>
				<SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
			</Grid.Background>
			<StackPanel Orientation="Horizontal">
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Save.png" 
										ToolTip="Save" ButtonCommand="{Binding SaveUserConfigurationCommand}" IsEnabled="{Binding CanSave}" />
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Refresh.png" 
										ToolTip="Reload" ButtonCommand="{Binding RefreshServerCommand}" IsEnabled="{Binding CanSave}" />
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/ConnectToServer.png" 
										ToolTip="Connect to server" ButtonCommand="{Binding ConnectToServerCommand}" IsEnabled="{Binding CanConnectToServer}" />
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Delete.png" 
										ToolTip="Remove server" ButtonCommand="{Binding DeleteServerCommand}" IsEnabled="{Binding CanDelete}" />
			</StackPanel>
		</Grid>
		<Grid Grid.Row="2" Grid.Column="1">
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition Height="Auto" />
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition />
			</Grid.ColumnDefinitions>

			<Grid Grid.RowSpan="2" Visibility="{Binding InformationIsVisible, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
				<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="Bold">Select server</TextBlock>
			</Grid>

			<Grid Visibility="{Binding ServerIsVisible, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition/>
				</Grid.RowDefinitions>

				<StackPanel>
					<Grid Margin="5,5,5,0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<Label Content="Name"/>
						<TextBox Grid.Column="1" Text="{Binding ActiveServerConnection.Name}" />
					</Grid>
					<Grid Margin="5,5,5,0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<Label Content="Enabled"/>
						<CheckBox Grid.Column="1" IsChecked="{Binding ActiveServerConnection.IsEnabled}" VerticalContentAlignment="Center" />
					</Grid>
					<Grid Margin="5,5,5,0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="Auto" />
						</Grid.ColumnDefinitions>

						<Label Content="Type"/>
						<ComboBox Grid.Column="1" ItemsSource="{Binding ConnectionTypes}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ActiveServerConnection.ConnectionTypeId}"/>
					</Grid>
					<Grid Margin="5,5,5,0" Visibility="{Binding ShowRemoteConnection, Converter={StaticResource NotBooleanToVisibilityConverter}, Mode=OneWay}">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<Label Content="Connection String"/>
						<TextBox Grid.Column="1" Text="{Binding ActiveServerConnection.ConnectionString}" />
					</Grid>
					<Grid Margin="5,5,5,0" Visibility="{Binding ShowRemoteConnection, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<Label Content="Remote Address"/>
						<TextBox Grid.Column="1" Text="{Binding ActiveServerConnection.RemoteAddress}" />
					</Grid>
				</StackPanel>
				<Grid Grid.Row="1" Margin="5,5,5,5">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="130" />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>

					<Label Content="Status"/>
					<TextBox Grid.Column="1" IsReadOnly="True" Text="{Binding StatusMessage, Mode=OneWay}" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" />
				</Grid>
			</Grid>
		</Grid>
	</Grid>
</views:MvxWpfView>
